/* Copyright 2021 Kerim Yalcin
**
**   Licensed under the Apache License, Version 2.0 (the "License");
**   you may not use this file except in compliance with the License.
**   You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
**   Unless required by applicable law or agreed to in writing, software
**   distributed under the License is distributed on an "AS IS" BASIS,
**   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**   See the License for the specific language governing permissions and
**   limitations under the License.
*/

#include "Window.hpp"
#include <iostream>

/***** public *****/

Agx::Window::Window(HINSTANCE pInstance) :
    WindowBase{pInstance} {
    
    mExtendedStyle  = 0;
    mStyle          = 0;
    
    mPosition_X     = CW_USEDEFAULT;
    mPosition_Y     = CW_USEDEFAULT;
    mWindow_Width   = CW_USEDEFAULT;
    mWindow_Heigth  = CW_USEDEFAULT;
    mWindow_Parent  = nullptr;
    mMenu           = nullptr;
    mParam          = nullptr;
}

void Agx::Window::set_WndClass_Name(const std::string& pWndClass_Name) {
    mWndClass_Name = pWndClass_Name;
}

void Agx::Window::set_WindowTitle(const std::string& pWindowTitle) {
    mWindow_Name = pWindowTitle;
}

const std::string& Agx::Window::get_WindowTitle() {
    return mWindow_Name;
}

void Agx::Window::set_Parent(const HWND pParent) {
    mWindow_Parent = pParent;
    mStyle |= WS_CHILD;
}

void Agx::Window::change_Parent(const HWND pParent) {
    if (is_linked_withFrame()) {
        SetParent(get_WindowHandle(), pParent);
    }
}

void Agx::Window::enable_ThinLine_Border() {
    mStyle |= WS_BORDER;
}

void Agx::Window::change_ThinLine_Border_toEnabled() {
    mStyle |= WS_BORDER;
    if (is_linked_withFrame()) {
        SetWindowLongA(get_WindowHandle(), GWL_STYLE, mStyle);
        SetWindowPos(
            get_WindowHandle(),
            nullptr,
            0, 0, 0, 0,
            SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_FRAMECHANGED
        );
        mStyle = GetWindowLongA(get_WindowHandle(), GWL_STYLE);
    }
}

void Agx::Window::disable_ThinLine_Border() {
    if (mStyle & WS_BORDER) {
        mStyle ^= WS_BORDER;
    }
}

void Agx::Window::change_ThinLine_Border_toDisabled() {
    if (is_linked_withFrame()) {
        if (mStyle & WS_BORDER) {
            mStyle ^= WS_BORDER;
            SetWindowLongA(get_WindowHandle(), GWL_STYLE, mStyle);
            SetWindowPos(
                get_WindowHandle(),
                nullptr,
                0, 0, 0, 0,
                SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_FRAMECHANGED
            );
            mStyle = GetWindowLongA(get_WindowHandle(), GWL_STYLE);
        }
    }
}

void Agx::Window::draw() {
}